package toanstt.com;

import java.util.HashMap;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.media.SoundPool.OnLoadCompleteListener;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

public class Sound2
{
	public int HIT = 1;
	public int BOOM = 2;
	public int GOOD = 3;
	public int GREET =4;
	public int LOSE = 5;
	public int MAGIC = 6;
	public int MISS = 7;
	public int MYGOD = 8;
	public int NORMAL = 9;
	public int PERFECT = 10;
	public int THEME = 11;
	public int WIN = 12;
	public int ADD = 13;
	
	private  SoundPool mSoundPool;
	private  HashMap<Integer, Integer> mSoundPoolMap;
	AudioManager  mAudioManager;
	private static  Context mContext;
	float currentVolume;
	static int c;
	private AudioManager aMgr;
	public Sound2()
	{
		initSounds();
	}
	public  void initSounds()
	{
		mContext = DiamondLinkinActivity.context;
		aMgr = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
		  mSoundPool = new SoundPool(16, AudioManager.STREAM_MUSIC, 0);
		  mSoundPoolMap = new HashMap<Integer, Integer>();
		  AddSounds();
		  currentVolume = ((float)aMgr.getStreamVolume(AudioManager.STREAM_MUSIC)) / 
					 ((float)aMgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
	}
	public  void addSound(Context mContext, int index, int SoundID)
	{
		
			  mSoundPoolMap.put(index, mSoundPool.load(mContext, SoundID, 1));
			
		//int k = mSoundPoolMap.put(index, mSoundPool.load(mContext, SoundID, 1)); 
		//Log.d("okddd",""+k);
	}
	public  void Play(int index) 
	{		
		  mSoundPool.play((Integer) mSoundPoolMap.get(index), currentVolume,currentVolume, 1, 0, 1.0f);
		 // mSoundPool.play(0,0.9f,0.9f, 1, 10, 1.0f);
	}
	public  void Stop(int index) 
	{		
		  //mSoundPool.play((Integer) mSoundPoolMap.get(index), currentVolume,currentVolume, 1, 0, 1.0f);
		  mSoundPool.stop((Integer) mSoundPoolMap.get(index));
		 // mSoundPool.play(0,0.9f,0.9f, 1, 10, 1.0f);
	}
	public  void PlayLoop(int index) 
	{		
		mSoundPool.play((Integer) mSoundPoolMap.get(index), currentVolume,currentVolume, 1, 100, 1.0f);
		  //mSoundPool.play((Integer) mSoundPoolMap.get(index), currentVolume,currentVolume, 1000, 1, 1.0f);
		  
		 // mSoundPool.play(0,0.9f,0.9f, 1, 10, 1.0f);
	}
	public  void AddSounds()
	{
		//addSound(mContext,1, R.raw.perfect);
		//addSound(mContext,2, R.raw.theme);
		//addSound(mContext,3, R.raw.win);
		//addSound(mContext,4, R.raw.lose);
		addSound(mContext,HIT ,R.raw.hit);
		addSound(mContext,BOOM ,R.raw.boom);
		addSound(mContext,GOOD ,R.raw.good);
		addSound(mContext,LOSE ,R.raw.lose);
		addSound(mContext,MAGIC ,R.raw.magic);
		addSound(mContext,MISS ,R.raw.miss);
		addSound(mContext,MYGOD ,R.raw.mygod);
		addSound(mContext,NORMAL ,R.raw.nornal);
		addSound(mContext,PERFECT ,R.raw.perfect);
		addSound(mContext,THEME ,R.raw.theme);
		addSound(mContext,WIN ,R.raw.win);
		addSound(mContext,ADD ,R.raw.add);
		
	}
	public void Exit()
	{
		mSoundPool.stop(THEME);
		
	}
//	public void onCreate(Bundle savedInstanceState)
//	{
//        super.onCreate(savedInstanceState);
// youraudioclass.initSounds();
// youraudioclass.addSound(this, 1, r.raw.sound1);
// youraudioclass.addSound(this, 2, r.raw.sound2);
// youraudioclass.addSound(this, 2, r.raw.boom);
//  //and so on, just stick the mp3/wav/whatever in a res/raw folder.
//  //the number is just for your own reference for when you want to play the sound
//}
}
